/**
 Copyright (C) 2013 Yuyao Liang

 This source code is release under the BSD License.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.

 Created on Nov 20, 2013 9:45:09 PM
 */
package com.googlecode.backtest.rule.ta;

import java.util.List;

import com.googlecode.backtest.dataset.IBackTestStockDataset;
import com.googlecode.backtest.dataset.provider.IDataProvider;
import com.googlecode.backtest.rule.ISourceAlgorithm;
import com.googlecode.backtest.rule.ITAParameters;

/**
 * @author lianyuy
 * 
 */
public class Input_Algorithm extends
		TABackTestAlgorithm<IBackTestStockDataset, ITAParameters> implements
		ISourceAlgorithm<IBackTestStockDataset, ITAParameters> {

	private final String ID = getClass().getName();
	private final String VERSION = Messages
			.getString("Input_Algorithm.VERSION"); //$NON-NLS-1$
	private final String Key = Messages.getString("Input_Algorithm.key"); //$NON-NLS-1$
	private int index;
	private IDataProvider<IBackTestStockDataset> provider = null;

	/**
	 * 
	 * @param id
	 * @param data_ids
	 */
	public Input_Algorithm(String id, List<String> data_ids,
			ITAParameters parameter) {
		super(id, data_ids, parameter);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.googlecode.backtest.rule.IBackTestAlgorithm#calculate(java.util.List,
	 * java.lang.Object)
	 */
	@Override
	public boolean calculate(List<IBackTestStockDataset> dataset) {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.googlecode.backtest.rule.BackTestAlgorithm#getResult()
	 */
	@Override
	public IBackTestStockDataset getResult() {
		if (provider == null) {
			return null;
		}
		index = 0;
		String stock = provider.getStock(index);
		if (stock.isEmpty()) {
			return null;
		}

		return provider.getDataset(stock);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.googlecode.backtest.rule.IAlgorithm#getKey()
	 */
	@Override
	public String getKey() {
		return Key;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.srclib.base.IDable#getID()
	 */
	@Override
	public String getID() {
		return ID;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.srclib.base.Versionable#getVersion()
	 */
	@Override
	public String getVersion() {
		return VERSION;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.googlecode.backtest.rule.ta.TABackTestAlgorithm#setDataProvider(com
	 * .googlecode.backtest.document.IDataProvider)
	 */
	@Override
	public void setDataProvider(IDataProvider<IBackTestStockDataset> provider) {
		this.provider = provider;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.googlecode.backtest.rule.ISourceAlgorithm#run()
	 */
	@Override
	public boolean run() {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.googlecode.backtest.rule.ISourceAlgorithm#getDataProvider()
	 */
	@Override
	public IDataProvider<IBackTestStockDataset> getDataProvider() {
		return provider;
	}

}
